home *** CD-ROM | disk | FTP | other *** search
Text File | 2008-06-19 | 63.0 KB | 1,655 lines |
- const YB_ADDBOOKMARK_NOTES_MAX_LENGTH = 255;
- const YB_ADDBOOKMARK_TITLE_MAX_LENGTH = 255;
- var yAddBookMark = {
- post: {
- title: '',
- url: '',
- tags: null,
- systemTags: null,
- notes: '',
- shared: "true",
- rss: false,
- shortcut: "",
- postData: "",
- added_date: null
- },
- config: {
- maxSuggestedTags: 8,
- midColMaxChars: null,
- inputTagBoxID: 'tb_ybTags',
- traditionalAddPref: 2,
- rssTag: 'firefox:rss',
- emptyTag: 'system:unfiled',
- dialogID: 'dlg_AddYBookMark',
- specialTagPref: 'system:',
- shortcutTagPref: 'shortcut:',
- attr_selected: "yb_selected",
- attr_related: "yb_related",
- sgstTagPrefix: "lbl_sgstTag_",
- class_mousedOver: "moused-over-tag",
- class_mousedOut: "moused-out-tag",
- bmLetURLPref: "javascript:"
- },
- inputTagBox: null,
- editOp: false,
- blankEntry: false,
- keywordInput: false,
- existingEntry: null,
- kDelContractID: "@yahoo.com/socialstore/delicious;1",
- kLocalStoreContractID: "@mozilla.org/ybookmarks-store-service;1",
- kSyncServiceContractID: "@mozilla.org/ybookmarks-sync-service;1",
- nSgstTagInserts: 0,
- nameInputElt: null,
-
- localStore: null,
- syncService: null,
-
- _bookmarkID: null,
- _microsummaries: null,
- __mss: null,
- originalGetShortcutOrURI: null,
-
- get _mss() {
- if (!this.__mss) {
- this.__mss = Components.classes["@mozilla.org/microsummary/service;1"];
- if (this.__mss) {
- this.__mss = this.__mss.getService( Components.interfaces.nsIMicrosummaryService );
- }
- }
- return this.__mss;
- },
-
-
- __ios: null,
- get _ios() {
- if (!this.__ios)
- this.__ios = Components.classes["@mozilla.org/network/io-service;1"].
- getService(Components.interfaces.nsIIOService);
- return this.__ios;
- },
-
- _prefs: null,
- get prefs() {
- if( this._prefs == null ) {
- this._prefs = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefBranch);
- }
- return this._prefs;
- },
-
- open: function( url, title, charset, isWebPanel, notes, feedUrl, blankEntry, postData, keywordInput, userSelectedTag ) {
- // check if user is logged in
- if( !YBidManager.isUserLoggedIn() ) {
- YBidManager.promptUserLogin();
-
- try {
- if (window.ybLoginWindowFlag == "display") {
- YBPopupWindow.showLoginWindow();
- }
- } catch(e) {
- // do nothing
- }
-
- return;
- }
-
- if( url == null ) {
- url = '';
- }
- if( title == null ) {
- title = '';
- }
- if( blankEntry == null ) {
- blankEntry = false;
- }
- if( keywordInput == null ) {
- keywordInput = false;
- }
-
- this.post.url = url;
- this.post.title = title;
- this.post.notes = (notes?notes:'');
- this.post.charset = (charset?charset:"");
- this.post.isWebPanel = (isWebPanel?isWebPanel:false);
- this.post.tags = new Array();
- this.post.shortcut = "";
- this.post.systemTags = null;
-
- if( postData != null ) {
- this.post.postData = postData;
- }
- else {
- this.post.postData = "";
- }
-
- if (feedUrl) {
- this.post.url = feedUrl;
- this.post.rss = true;
- } else {
- this.post.rss = false;
- }
-
- if( ( this.post.url.length == 0 ) && ( blankEntry != true ) ) {
- this._getDoc( window );
- }
-
- var defaultSharing = 0;
- try {
- defaultSharing = this.prefs.getIntPref( "extensions.ybookmarks@yahoo.sharemode" );
- // 1 - private 2 - public
- defaultSharing = ( defaultSharing == 1 ? "false" : "true" );
- } catch ( e ) {
- defaultSharing = "true";
- }
-
- this.post.shared = defaultSharing;
-
- if( blankEntry != true ) {
- this._checkForEditOperation();
- }
- //handle classic mode
- if( (this._checkAddMechPref() == this.config.traditionalAddPref) || (ybookmarksUtils.getExtensionMode() == YB_EXTENSION_MODE_CLASSIC)) {
- this._traditionalAdd();
- }
- else {
- var rv = { openTraditionalAdd: false };
-
- window.openDialog( "chrome://ybookmarks/content/yAddBookMark.xul",
- "AddBookMarks",
- "chrome,dialog,centerscreen,resizable=no",
- this.post, this.editOp, blankEntry, keywordInput, rv, userSelectedTag );
- }
- },
-
- _getLocalStore: function() {
- if( this.localStore == null ) {
- try {
- this.localStore = ( Components.classes[ this.kLocalStoreContractID ].
- getService( Components.interfaces.nsIYBookmarksStoreService ) );
- }
- catch( e ) {
- yDebug.print( "couldn't get ystore!", YB_LOG_MESSAGE );
- return;
- }
- }
- },
-
- _getSyncService: function() {
- if( this.syncService == null ) {
- try {
- this.syncService = ( Components.classes[this.kSyncServiceContractID].
- getService(Components.interfaces.nsIYBookmarkSyncService) );
- }
- catch( e ) {
- yDebug.print( "couldn't get syncService!", YB_LOG_MESSAGE );
- return;
- }
- }
- },
-
- _checkForEditOperation: function() {
- this._getLocalStore();
- var bookmarkResource = this.localStore.isBookmarked( this.post.url );
- yDebug.print ( "Existing entry for " + this.post.url + " => " + bookmarkResource );
- if( bookmarkResource == null ) {
- this.editOp = false;
- }
- else {
- // check if the bookmark is a child of livemark. Bookmark object within Livemark is not
- // eligible for edit operations.
- var bookmarkType = this.localStore.resolveBookmarkResourceType( bookmarkResource );
- if ( bookmarkType == "LiveBookmark" ) {
- this.editOp = false;
- } else {
- this.editOp = true;
- this.existingEntry = this.localStore.getBookmark( this.post.url );
-
- // see if microsummary was used while editing. If keep the title same as
- // that of the web page
- var microSummaries = null;
- if (this._mss ) {
- try { // 2007-01-11 cmyang: need this try/catch block because the mss barfs on non HTML/XML (i.e images, etc)
- microSummaries = this._mss.getMicrosummaries( this._ios.newURI ( this.post.url, null, null ),
- this.localStore.isBookmarked( this.post.url )
- );
- } catch(e) {
- yDebug.print("Microsummary Service error with URL '" + this.post.url + "': " + e + " --> Ignoring Error");
- }
- }
- if ( !microSummaries || !microSummaries.Enumerate().hasMoreElements() ) {
- this.post.title = this.existingEntry.name;
- }
- this.post.notes = this.existingEntry.description;
- this.post.shared = this.existingEntry.shared;
- this.post.localOnly = this.existingEntry.localOnly;
- this.post.shortcut = this.existingEntry.shortcut;
- this.post.postData = this.existingEntry.postData;
- this.post.added_date = this.existingEntry.added_date;
-
- //todo: load shared attribute here
-
- yDebug.print( "name: " + this.existingEntry.name );
- yDebug.print( "url: " + this.existingEntry.url );
- yDebug.print( "description: " + this.existingEntry.description );
- yDebug.print( "Shared: " + this.existingEntry.shared );
- yDebug.print( "localOnly: " + this.existingEntry.localOnly );
- yDebug.print( "postData: " + this.existingEntry.postData );
- yDebug.print( "added_date: " + this.existingEntry.added_date );
-
- var tag, tags = this.existingEntry.tags.enumerate();
- while( tags.hasMoreElements() ) {
- tag =
- ( tags.getNext().QueryInterface( Components.interfaces.nsISupportsString ) ).data;
- this.post.tags.push( tag );
- }
- }
- }
- },
-
- urlClick: function() {
- var txtbx = document.getElementById( 'tb_yBookmarkURL' );
- var lbl = document.getElementById( 'lbl_yBookmarkURL' );
- lbl.hidden = true;
- txtbx.hidden = false;
- txtbox.focus();
- },
-
- init: function() {
-
- try {
- this.post = window.arguments[ 0 ];
- this.editOp = window.arguments[ 1 ];
- this.blankEntry = window.arguments[ 2 ];
- this.keywordInput = window.arguments[ 3 ];
- this.userSelectedTag = window.arguments[ 5 ];
- } catch( e ) { }
-
- var elt;
-
- var txtbx = document.getElementById( 'tb_yBookmarkURL' );
- var lbl = document.getElementById( 'lbl_yBookmarkURL' );
- var btn_delete = document.getElementById( 'btn_delete' );
-
- this.strings = document.getElementById("ybookmarks-strings");
- this.config.midColMaxChars =
- ( document.getElementById( "tb_yBookmarkURL" ) ).getAttribute( "cols" );
-
- if( this.post.url.length > ( this.config.midColMaxChars - 3 ) ) {
- lbl.value = this.post.url.substr( 0, this.config.midColMaxChars - 3 );
- lbl.value += "...";
- }
- else {
- lbl.value = this.post.url;
- }
- txtbx.value = this.post.url;
-
- if( this.editOp || ( this.blankEntry == true ) || ( this.keywordInput == true ) ) {
- document.getElementById( "rw_keywordInput" ).hidden = false;
- }
- else {
- ( document.getElementById( "tb_yBookmarkKeyword" ) ).setAttribute( "tabindex", "-1" );
- }
-
- if( this.editOp || ( this.blankEntry == true ) ) {
- lbl.hidden = true;
- txtbx.focus();
- btn_delete.hidden = false;
- }
- else {
- lbl.hidden = false;
- lbl.setAttribute( "class", this.config.class_mousedOut );
- lbl.setAttribute( "onclick", "yAddBookMark.urlClick();" );
- txtbx.hidden = true;
- txtbx.setAttribute( "tabindex", "-1" );
- ( document.getElementById( "tb_yBookmarkName" ) ).focus();
- btn_delete.hidden = true;
- }
-
- document.getElementById( 'tb_yBookmarkName' ).value = this.post.title;
- document.getElementById( 'menu_yBookmarkName' ).value = this.post.title;
- document.getElementById( "userEnteredNameItem").label = this.post.title;
- this.nameInputElt = 'tb_yBookmarkName';
-
- document.getElementById('tb_yBookmarkNotes').setAttribute("oninput", "yAddBookMark.updateNotesCount();");
-
- this.inputTagBox = document.getElementById( this.config.inputTagBoxID );
-
- /**
- * Hack to hide value column and add color
-
- this.inputTagBox.popup.treecols.firstChild.hidden = "true";
- this.inputTagBox.popup.tree.childNodes[1].style.color = "blue";
- */
-
- if( this.post.notes.length > 0 ) {
- elt = document.getElementById( 'tb_yBookmarkNotes' );
- elt.value = this.post.notes;
- }
-
- if ( this.post.tags ) {
- for( var i = 0; i < this.post.tags.length; ++i ) {
- // hide the implicit tags
- if( !this._isSystemTag( this.post.tags[ i ] ) ) {
- yDebug.print( "going to add " + this.post.tags[ i ] );
- this._addToUserTags( this.post.tags[ i ] );
- }
- else {
- if( !this.post.systemTags ) {
- this.post.systemTags = new Array();
- }
- this.post.systemTags.push( this.post.tags[i] );
- }
- }
- }
-
- if(this.userSelectedTag && (this.post.tags.indexOf(this.userSelectedTag) == -1)) {
- this._addToUserTags( this.userSelectedTag );
- }
-
- if( this.editOp == true ) {
- document.title =
- document.getElementById( this.config.dialogID ).getAttribute( "editTitle" );
- document.getElementById('img_dlgTitle').setAttribute( "src", "chrome://ybookmarks/skin/deliciousEditBookmark.gif" );
- }
- else {
- document.title =
- document.getElementById( this.config.dialogID ).getAttribute( "addTitle" );
- document.getElementById('img_dlgTitle').setAttribute( "src", "chrome://ybookmarks/skin/deliciousSaveaBookmark.gif" );
- }
-
- var noShareCheckbox = document.getElementById( "cb_noShare" );
- if (this.post.shared && this.post.shared == "false") {
- noShareCheckbox.checked = true;
- }
-
- var showLocalOnlyOption;
- try {
- showLocalOnlyOption = this.prefs.getBoolPref("extensions.ybookmarks@yahoo.show.localonly.option");
- } catch(e) {
- showLocalOnlyOption = false;
- }
-
- if (showLocalOnlyOption) {
- var localOnlyCheckbox = document.getElementById("cb_localOnly");
- localOnlyCheckbox.hidden = false;
- if (this.post.localOnly && this.post.localOnly == "true") {
- localOnlyCheckbox.checked = true;
- noShareCheckbox.checked = true;
- noShareCheckbox.disabled = true;
- }
- }
-
- document.getElementById( "tb_yBookmarkKeyword" ).value = this.post.shortcut;
-
- if( this.post.url.substr( 0, this.config.bmLetURLPref.length ) == this.config.bmLetURLPref ) {
- noShareCheckbox.checked = true;
- noShareCheckbox.disabled = true;
- }
- else if( this.post.url != '' ) {
- this._querySuggestedTags();
- }
-
- var lbl_origPostInfo = document.getElementById( "lbl_origPostInfo" );
- if( this.editOp == true ) {
- var added_date = new Date(this.post.added_date / 1000);
- yDebug.print("*** added_date = " + added_date);
- lbl_origPostInfo.value =
- this.strings.getFormattedString("extensions.ybookmarks.edit_dialog.originally_posted_on",
- [
- added_date.getFullYear(),
- added_date.getMonth() + 1,
- added_date.getDate(),
- added_date.getHours(),
- added_date.getMinutes()
- ]);
- lbl_origPostInfo.hidden = false;
- } else {
- lbl_origPostInfo.hidden = true;
- }
-
- try {
- this._initMicrosummary();
- }
- catch( e ) {
- yDebug.print( "exception while executing _initMicrosummary: " + e, YB_LOG_MESSAGE );
- }
-
- this._resetSaveButton();
-
- document.getElementById( "lbl_userName" ).setAttribute(
- "value", deliciousService.getUserName() );
-
- if( this.post.notes.length == 0 ) {
- var wm = Components.classes[ "@mozilla.org/appshell/window-mediator;1" ]
- .getService( Components.interfaces.nsIWindowMediator );
- var browserWin = wm.getMostRecentWindow( "navigator:browser" );
- var selObj = browserWin.content.getSelection();
- if( selObj ) {
- var str = selObj.toString();
- if( str && str.length > 0 ) {
- ( document.getElementById( "tb_yBookmarkNotes" ) ).setAttribute( "value", str );
- }
- }
- }
-
- /*
- elt = document.getElementById( "lbl_popTagsHelp" );
- elt.setAttribute( "value", elt.getAttribute( "value" ) + deliciousService.getServiceName() );
- */
- this.updateNotesCount();
- //Set focus on the tags field.
- ( document.getElementById( "tb_ybTags" ) ).focus();
- },
-
- uninit : function() {
- },
-
- _isSystemTag: function( tag ) {
- if( tag.substr( 0, this.config.specialTagPref.length ) == this.config.specialTagPref ) {
- return true;
- }
- if( tag.substr( 0, this.config.shortcutTagPref.length ) == this.config.shortcutTagPref ) {
- return true;
- }
- if( tag == this.config.rssTag ) {
- return true;
- }
- return false;
- },
-
- _initMicrosummary: function() {
- if (!this._mss) {
- yDebug.print ( "Microsummary is not available in this version of firefox. Please upgrade to Firefox 2.x" );
- document.getElementById( "menu_yBookmarkName" ).setAttribute( "droppable", "false" );
- return;
- }
-
- if ( this.post.url.length <= 0 ) {
- yDebug.print ( "Nothing to bookmark here" );
- document.getElementById( "menu_yBookmarkName" ).setAttribute( "droppable", "false" );
- return;
- }
-
- this._getLocalStore();
- this._bookmarkID = this.localStore.isBookmarked( this.post.url );
- var uri = this._ios.newURI ( this.post.url, null, null );
- this._microsummaries = this._mss.getMicrosummaries( uri,
- this._bookmarkID
- );
- this._observer._self = this;
- this._microsummaries.addObserver(this._observer);
- this.updateMicrosummary();
- },
-
- _observer: {
-
- interfaces: [ Components.interfaces.nsIMicorsummaryObserver, Components.interfaces.nsISupports ],
-
- onContentLoaded: function(microsummary) {
- this._self.updateMicrosummary();
- },
-
- onElementAppended: function(microsummary) {
- this._self.updateMicrosummary();
- }
- },
-
- onInput: function( elt ) {
- if( elt.id == "menu_yBookmarkName" ) {
- var nameField = document.getElementById( "menu_yBookmarkName" );
- var nameItem = document.getElementById( "userEnteredNameItem" );
- nameItem.label = nameField.value;
- }
- this._resetSaveButton();
- // check if bookmarklet is being changed
- if( ( this.editOp ) && ( elt.id == "tb_yBookmarkURL" ) ) {
- var urlField = document.getElementById( "tb_yBookmarkURL" );
- var cb = document.getElementById( "cb_noShare" );
- if( urlField.value.substr( 0, this.config.bmLetURLPref.length ) == this.config.bmLetURLPref ) {
- cb.checked = true;
- cb.disabled = true;
- }
- else {
- cb.disabled = false;
- }
- }
- },
-
- updateNotesCount:function() {
- try {
-
- var notesInput = document.getElementById("tb_yBookmarkNotes");
- /*if (notesInput.textLength > YB_ADDBOOKMARK_NOTES_MAX_LENGTH) {
- notesInput.value = notesInput.value.substring(0, YB_ADDBOOKMARK_NOTES_MAX_LENGTH);
- }*/
-
- var notesCount = document.getElementById("lbl_notesCount");
- var charsRemaining = YB_ADDBOOKMARK_NOTES_MAX_LENGTH - notesInput.textLength;
- var numString = yAddBookMark.strings.getFormattedString("extensions.ybookmarks.edit_dialog.name.count",
- [ charsRemaining ]);
- notesCount.value = numString;
- if (charsRemaining < 0) {
- notesCount.setAttribute("class", "overflowed")
- } else {
- notesCount.setAttribute("class", "")
- }
- } catch (e) {
- yDebug.print("updateNotesCount(): " + e);
- }
- },
-
- onSelectLocalOnlyOption : function(event) {
-
- var noShareCheckbox = document.getElementById( "cb_noShare" );
- if (event.target.checked) {
- noShareCheckbox.checked = true;
- noShareCheckbox.disabled = true;
- }
- else {
- if ( this.post.url.substr( 0, this.config.bmLetURLPref.length ) == this.config.bmLetURLPref ) {
- noShareCheckbox.checked = true;
- noShareCheckbox.disabled = true;
- }
- else {
- noShareCheckbox.disabled = false;
- }
- }
- },
-
- _resetSaveButton: function() {
- var okButton = document.getElementById( "btn_save" );
- var nameField = document.getElementById( this.nameInputElt );
- var urlField = document.getElementById( "tb_yBookmarkURL" );
- okButton.disabled =
- ( nameField.value.length == 0 || urlField.value.length == 0 ) ? true : false;
- },
-
- updateMicrosummary: function() {
- if (!this._microsummaries)
- return;
-
- var summaryList = document.getElementById( "menu_yBookmarkName" );
- var microsummaryPopup = document.getElementById( "microsummaryMenuPopup" );
-
- while ( microsummaryPopup.childNodes.length > 2 ) {
- microsummaryPopup.removeChild ( microsummaryPopup.lastChild );
- }
-
- var enumerator = this._microsummaries.Enumerate();
- if ( enumerator.hasMoreElements() ) {
- summaryList.setAttribute( "droppable", "true" );
- } else {
- summaryList.setAttribute( "droppable", "false" );
- }
-
- var activeMicrosummary = null;
- if ( summaryList.menuBoxObject.activeChild ) {
- activeMicrosummary = summaryList.menuBoxObject.activeChild.microsummary;
- }
-
- var nInserts = 0;
- while ( enumerator.hasMoreElements() ) {
- var microsummary = enumerator.getNext().QueryInterface ( Components.interfaces.nsIMicrosummary );
- if ( microsummary.content ) {
- var menuitem = document.createElement ( "menuitem" );
- menuitem.setAttribute( "label", microsummary.content );
- // for commit use
- menuitem.microsummary = microsummary;
- microsummaryPopup.appendChild ( menuitem );
- ++nInserts;
-
- // select the menu item, if this microsummary is the one used while bookmarking earlier
- if ( this._bookmarkID && this._mss.isMicrosummary( this._bookmarkID, microsummary ) ) {
- summaryList.selectedItem = menuitem;
- }
-
- if ( activeMicrosummary && microsummary == activeMicrosummary ) {
- summaryList.menuBoxObject.activeChild = menuitem;
- }
- } else {
- microsummary.update();
- }
- }
- if( ( nInserts > 0 ) && ( this.nameInputElt == "tb_yBookmarkName" ) ) {
- // hide the simple text box and show the menupopup
- var elt = document.getElementById( "tb_yBookmarkName" );
- elt.hidden = true;
- elt.setAttribute( "tabindex", "-1" );
- elt = document.getElementById( "menu_yBookmarkName" );
- elt.hidden = false;
- this.nameInputElt = "menu_yBookmarkName";
- document.getElementById("lbl_nameCount").hidden = true;
- sizeToContent();
- if( !this.editOp ) { // URL textbox retains focus in edit dialog
- elt.focus();
- }
- }
- },
-
- _getDoc: function( currWindow ) {
- var browser = currWindow.getBrowser();
- var webNav = browser.webNavigation;
- if( webNav.currentURI ) {
- this.post.url = webNav.currentURI.spec;
- }
- if( webNav.document.title ) {
- this.post.title = webNav.document.title;
- }
- else {
- this.post.title = this.post.url;
- }
- },
-
- _setSuggestions: function( tags, containerName, maxTags ) {
- if( maxTags == null ) {
- maxTags = tags.length; // use all available input tags
- }
- if( tags.length > 0 ) {
- var nElts = ( tags.length < maxTags ) ? tags.length : maxTags;
- var i, elt;
- var container = document.getElementById( containerName );
- var currBox = null, tag;
- var rowStrLen = 0, nInserts = 0;
- for( i = 0; ( nInserts < nElts ) && ( i < tags.length ); ++i ) {
- tag = ( tags.queryElementAt( i, Components.interfaces.nsISupportsString ) ).data;
- if( !this._isSystemTag( tag ) ) {
- if( ( currBox == null ) || ( rowStrLen >= ( this.config.midColMaxChars - 15 ) ) ) {
- if( currBox != null ) {
- container.appendChild( currBox );
- }
- currBox = document.createElement( "hbox" );
- rowStrLen = 0;
- }
- elt = this._createTagLabel( tag );
- currBox.appendChild( elt );
- ++nInserts;
- rowStrLen += tag.length;
- }
- }
- if( currBox != null ) {
- container.appendChild( currBox );
- container.hidden = false;
- sizeToContent();
- }
- }
- },
-
- _createTagLabel: function( tag ) {
- var i, elt, newElt = document.createElement( "label" );
- var newEltId = this.config.sgstTagPrefix + this.nSgstTagInserts;
- newElt.setAttribute( "id", newEltId );
- newElt.setAttribute( "value", tag );
- newElt.setAttribute( "class", this.config.class_mousedOut );
- newElt.setAttribute( this.config.attr_selected, "false" );
- newElt.setAttribute( "onclick", "yAddBookMark.tagClick( this );" );
- newElt.setAttribute( "tabindex", "-1" );
- newElt.addEventListener( "mouseover", yAddBookMark.tagMouseOver, false );
- newElt.addEventListener( "mouseout", yAddBookMark.tagMouseOut, false );
- if( this.editOp ) {
- for( i = 0; i < this.post.tags.length; ++i ) {
- if( tag == this.post.tags[ i ] ) {
- newElt.setAttribute( "class", this.config.class_mousedOver );
- newElt.setAttribute( this.config.attr_selected, "true" );
- break;
- }
- }
- }
- ++this.nSgstTagInserts;
- return newElt;
- },
-
- _createRelations: function() {
- var i, j, hash = {}, elt, tag;
- for( i = 0; i < this.nSgstTagInserts; ++i ) {
- elt = document.getElementById( this.config.sgstTagPrefix + i );
- tag = elt.getAttribute( "value" );
- if( !hash[ tag ] ) {
- hash[ tag ] = new Array();
- }
- hash[ tag ].push( elt );
- }
- for( tag in hash ) {
- if( hash[ tag ].length > 1 ) {
- for( i = 0; i < hash[ tag ].length; ++i ) {
- for( j = 0; j < hash[ tag ].length; ++j ) {
- if( i != j ) {
- this._addRelative( hash[ tag ][ i ], hash[ tag ][ j ] );
- }
- }
- }
- }
- hash[ tag ] = null;
- }
- },
-
- _addRelative: function( obj, relative ) {
- var links = obj.getAttribute( this.config.attr_related );
- if( links.length == 0 ) {
- links = relative.getAttribute( "id" );
- }
- else {
- links = links + ',' + relative.getAttribute( "id" );
- }
- obj.setAttribute( this.config.attr_related, links );
- },
-
- tagClick: function( link ) {
- var idx = ybookmarksUtils.containsTag( this.inputTagBox.value, link.value );
- if( idx == -1 ) {
- this._addToUserTags( link.value );
- this._setTagAttribs( link, this.config.class_mousedOver, "true" );
- }
- else {
- this._removeTag( link.value, idx );
- this._setTagAttribs( link, this.config.class_mousedOut, "false" );
- }
- ( document.getElementById( "tb_ybTags" ) ).focus();
- },
-
- _setTagAttribs: function( elt, classVal, selectVal ) {
- elt.setAttribute( "class", classVal );
- elt.setAttribute( this.config.attr_selected, selectVal );
- var relationsStr = elt.getAttribute( this.config.attr_related );
- if( relationsStr.length > 0 ) {
- var relations = relationsStr.split( "," );
- var i, relatedElt;
- for( i = 0; i < relations.length; ++i ) {
- relatedElt = document.getElementById( relations[ i ] );
- relatedElt.setAttribute( "class", classVal );
- relatedElt.setAttribute( this.config.attr_selected, selectVal );
- }
- }
- },
-
- tagMouseOver: function( event ) {
- if( ( event.target.getAttribute( yAddBookMark.config.attr_selected ) == "false" ) &&
- ( event.target.getAttribute( "class" ) != yAddBookMark.config.class_mousedOver ) ) {
- event.target.setAttribute( "class", yAddBookMark.config.class_mousedOver );
- }
- },
-
- tagMouseOut: function( event ) {
- if( ( event.target.getAttribute( yAddBookMark.config.attr_selected ) == "false" ) &&
- ( event.target.getAttribute( "class" ) != yAddBookMark.config.class_mousedOut ) ) {
- event.target.setAttribute( "class", yAddBookMark.config.class_mousedOut );
- }
- },
-
- _querySuggestedTags: function() {
- var cb = {
- onload: function( dataArr ) {
- data = dataArr.queryElementAt( 0, Components.interfaces.nsIPropertyBag );
- var iter = data.enumerator, elt, arr, i, tag;
- while( iter.hasMoreElements() ) {
- elt = iter.getNext().QueryInterface( Components.interfaces.nsIProperty );
- arr = elt.value.QueryInterface( Components.interfaces.nsIArray );
- switch( elt.name ) {
- case "recommended":
- yAddBookMark._setSuggestions( arr, "hbx_recTags",
- yAddBookMark.config.maxSuggestedTags );
- break;
- case "network":
- // UI should include all network tags
- yAddBookMark._setSuggestions( arr, "hbx_nwTags" );
- break;
- case "popular":
- yAddBookMark._setSuggestions( arr, "hbx_popTags",
- yAddBookMark.config.maxSuggestedTags );
- break;
- }
- // link same tags in different sets
- yAddBookMark._createRelations();
- }
- },
- onerror: function( event ) {
- }
- };
-
- var delStore;
- try {
- delStore = ( Components.classes[ this.kDelContractID ].
- getService( Components.interfaces.nsISocialStore ) );
- delStore.getSuggestedTags( this.post.url, cb );
- }
- catch( e ) {
- yDebug.print( "exception: " + e, YB_LOG_MESSAGE );
- }
- },
-
- deleteBookMark: function() {
- var func = "yAddBookMark.js: deleteBookMark(): ";
- yDebug.print(func + "this.post.url = \"" + this.post.url + "\"");
- if( this.post.url.length > 0 ) { // Check that URL is valid before trying to delete
- this._getLocalStore();
- this._getSyncService();
-
- yDebug.print(func + "about to delete this.post.url = \"" + this.post.url + "\"");
-
- var promptService =
- Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- var isConfirmed = promptService.confirm(window,
- "Delete bookmark?",
- "Are you sure you want to delete this bookmark?");
- if (!isConfirmed) {
- return false;
- }
-
- this.localStore.deleteBookmark( this.post.url );
- yDebug.print(func + "deleteBookmark on this.post.url = \"" + this.post.url + "\"");
- var wpost = { url : this.post.url };
- wpost.wrappedJSObject = wpost;
- yDebug.print(func + "adding txn for deleteBookmark on this.post.url = \"" + this.post.url + "\"");
- this.localStore.addTransaction("deleteBookmark", 0, wpost);
- yDebug.print(func + "added txn for deleteBookmark on this.post.url = \"" + this.post.url + "\"");
-
- // Notify the sync service that we have a pending transaction to apply to del.icio.us
- var os = Components.classes["@mozilla.org/observer-service;1"]
- .getService(Components.interfaces.nsIObserverService);
- os.notifyObservers(null, "ybookmark.processTransactions", null);
- os.notifyObservers(null, "ybookmark.bookmarkDeleted", null);
- }
-
- this._removeObservers();
- window.close();
- return true;
- },
-
- _containsShortcut: function(aTags) {
- for (var i=0; i < aTags.length; i++) {
- var tag = aTags[i];
- var index = tag.indexOf(this.config.shortcutTagPref);
- if (index != -1) {
- index += this.config.shortcutTagPref.length;
- return tag.substr(index);
- }
- }
- return "";
- },
-
- _exciseShortcuts: function (aTags) {
- var result = [];
- for (var i=0; i < aTags.length; i++) {
- var tag = aTags[i];
- var index = tag.indexOf(this.config.shortcutTagPref);
- if (index != 0) {
- result.push(tag);
- }
- }
-
- return result;
- },
-
- saveBookMark: function() {
-
- var notesInput = document.getElementById("tb_yBookmarkNotes");
- var notesCount = document.getElementById("lbl_notesCount");
- var charsRemaining = YB_ADDBOOKMARK_NOTES_MAX_LENGTH - notesInput.textLength;
- if (charsRemaining < 0) {
- try {
- var truncateAutomatically = false;
- try {
- truncateAutomatically = this.prefs.getBoolPref("extensions.ybookmarks@yahoo.bookmark.notes.truncate_automatically");
- } catch (e) { }
-
- if (!truncateAutomatically) {
- var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
- getService(Components.interfaces.nsIPromptService);
- var title = document.title;
- var text = this.strings.getFormattedString("extensions.ybookmarks.edit_dialog.notes.count.limit",
- [YB_ADDBOOKMARK_NOTES_MAX_LENGTH])
- var truncate = this.strings.getString("extensions.ybookmarks.edit_dialog.notes.count.limit.truncate");
- var truncateCheck = { value: false };
-
- promptService.alertCheck(this, title, text, truncate, truncateCheck);
-
- if (truncateCheck.value) {
- this.prefs.setBoolPref("extensions.ybookmarks@yahoo.bookmark.notes.truncate_automatically", true);
- } else {
- notesInput.focus();
- return false;
- }
- }
-
- notesInput.value = notesInput.value.substr(0, YB_ADDBOOKMARK_NOTES_MAX_LENGTH);
-
- } catch (e) {
- yDebug.print("yAddBookMark.saveBookMark: error with notes count limit: " + e);
- }
- }
-
- if( this.blankEntry == true ) {
- this.post.url = ( document.getElementById( "tb_yBookmarkURL" ) ).value;
- }
-
- if( this.post.url.length > 0 ) {
- var elt;
-
- this._getLocalStore();
- this._getSyncService();
- var rv = window.arguments[ 4 ];
- var post;
-
- if( this.editOp ) {
- elt = document.getElementById( "tb_yBookmarkURL" );
- if( this.post.url != elt.value ) {
- this.localStore.deleteBookmark( this.post.url )
- var wpost = { url : this.post.url };
- wpost.wrappedJSObject = wpost;
- this.localStore.addTransaction("deleteBookmark", 0, wpost);
- if( elt.value.length == 0 ) { // user wants to delete the entry?
- var os = Components.classes["@mozilla.org/observer-service;1"]
- .getService(Components.interfaces.nsIObserverService);
- os.notifyObservers(null, "ybookmark.processTransactions", null);
- this._removeObservers();
- return;
- }
- this.post.url = elt.value;
- this.editOp = false;
- }
- }
-
- elt = document.getElementById( 'tb_yBookmarkURL' );
- this.post.url = elt.value;
-
- elt = document.getElementById( this.nameInputElt );
- elt.value = elt.value.substr(0, YB_ADDBOOKMARK_TITLE_MAX_LENGTH);
- this.post.title = elt.value;
-
- elt = document.getElementById( "tb_yBookmarkNotes" );
- if( elt.value.length > 0 ) {
- this.post.notes = elt.value;
- }
-
- elt = document.getElementById( "cb_noShare" );
- this.post.shared = (elt.checked?"false":"true");
-
- elt = document.getElementById( "cb_localOnly" );
- this.post.localOnly = (elt.checked? "true" : "false");
-
- elt = document.getElementById( "tb_yBookmarkKeyword" );
- this.post.shortcut = elt.value;
-
- yDebug.print ( "IS POST AN RSS => " + this.post.rss );
- this._getPostTags();
-
-
- if (this.editOp) {
- this.post.tags = this._exciseShortcuts(this.post.tags);
- } else {
- this.post.shortcut = this.post.shortcut ? this.post.shortcut : this._containsShortcut(this.post.tags);
- yDebug.print("shortcut found: " + this.post.shortcut);
- }
-
- if( yDebug.on() ) {
- this._dumpPost();
- }
-
- post = this.post;
- post.wrappedJSObject = post;
- if( this.editOp ) {
- this.localStore.editBookmark( this.post.url, this._createBookmarkObject());
- this.localStore.addTransaction("editBookmark", 0, post);
- }
- else {
- if ( this.post.rss ) {
- this.localStore.addLivemark( this.post.url, this.post.title,
- this.post.url,
- this.post.notes,
- this.post.tags.length, this.post.tags,
- this.post.shared,
- this.post.localOnly,
- true );
-
- } else {
- this.localStore.addBookmark( this.post.url, this.post.title,
- this.post.charset, this.post.isWebPanel, this.post.notes,
- this.post.shortcut,
- this.post.postData,
- this.post.tags.length, this.post.tags,
- this.post.shared,
- this.post.localOnly,
- true );
- }
- this.localStore.addTransaction("addBookmark", 0, post);
- }
-
- this._updateMicrosummary();
-
- var os = Components.classes["@mozilla.org/observer-service;1"]
- .getService(Components.interfaces.nsIObserverService);
- os.notifyObservers(null, "ybookmark.processTransactions", null);
- }
-
- this._removeObservers();
- window.close();
- },
-
- _updateMicrosummary: function() {
- // update micro summary too
- var nameElement = document.getElementById( "menu_yBookmarkName" );
- var microsummary = null;
- if ( nameElement.selectedItem ) {
- microsummary = nameElement.selectedItem.microsummary;
- }
- //this.post.microsummary = null;
- var bookmarkResource = this.localStore.isBookmarked( this.post.url );
- if ( microsummary ) {
- this._mss.setMicrosummary ( bookmarkResource, microsummary );
- } else {
- if ( this._mss && this._mss.hasMicrosummary (bookmarkResource ) ) {
- this._mss.removeMicrosummary ( bookmarkResource );
- }
- }
- },
-
- _createBookmarkObject: function() {
- const NSArray = new Components.Constructor( "@mozilla.org/array;1",
- Components.interfaces.nsIMutableArray );
- const NSString = new Components.Constructor( "@mozilla.org/supports-string;1",
- Components.interfaces.nsISupportsString );
- var tags = new NSArray();
- var i, str;
- for( i = 0; i < this.post.tags.length; ++i ) {
- str = new NSString();
- str.data = this.post.tags[ i ];
- tags.appendElement( str, false );
- }
- return {
- name: this.post.title,
- url: this.post.url,
- description: this.post.notes,
- tags: tags.QueryInterface( Components.interfaces.nsIArray ),
- shared: this.post.shared,
- shortcut: this.post.shortcut,
- postData: this.post.postData,
- localOnly : this.post.localOnly
- };
- },
-
- _dumpPost: function() {
- yDebug.print( "url: " + this.post.url );
- yDebug.print( "title: " + this.post.title );
- yDebug.print( "notes: " + this.post.notes );
- yDebug.print( "tags: " + this.post.tags );
- yDebug.print( "shared: " + this.post.shared );
- yDebug.print( "localOnly: " + this.post.localOnly );
- yDebug.print( "shortcut: " + this.post.shortcut );
- },
-
- cancelBookMark: function() {
- this._removeObservers();
- window.close();
- },
-
- _removeObservers: function() {
- if ( this._microsummaries ) {
- try {
- this._microsummaries.removeObserver( this._observer );
- } catch ( e ) {
- }
- }
- },
-
- _getPostTags: function() {
- if( this.post.tags == null ) {
- this.post.tags = new Array();
- }
- else {
- this.post.tags.length = 0;
- }
-
- this.post.tags = this.inputTagBox.value.split( /\s */ );
- if( this.editOp ) {
- if( this.post.systemTags ) {
- var i;
- for( i = 0; i < this.post.systemTags.length; ++i ) {
- this.post.tags.push( this.post.systemTags[ i ] );
- }
- }
- } else if( this.post.rss ) {
- yDebug.print ( "ADDING SYSTEM:RSS TO TAGS" );
- this.post.tags.push( this.config.rssTag );
- }
-
- if ( this.post.tags.length == 1 && !this.post.tags[0]) {
- this.post.tags = new Array();
- this.post.tags.push( this.config.emptyTag );
- }
-
- },
-
- _removeTag: function( tag, idx ) {
- var str = "";
- if( tag.length != this.inputTagBox.value.length ) {
- if( idx == 0 ) {
- str = this.inputTagBox.value.substr( tag.length + 1 );
- }
- else {
- str = this.inputTagBox.value.substr( 0, idx - 1 ) +
- this.inputTagBox.value.substr( idx + tag.length );
- }
- }
- this.inputTagBox.value = str;
- },
-
- _addToUserTags: function( tag ) {
- if( this.inputTagBox.value.length == 0 ) {
- this.inputTagBox.value = tag;
- }
- else {
- if (this.inputTagBox.value.charAt(this.inputTagBox.value.length-1) == " ")
- this.inputTagBox.value += tag;
- else
- this.inputTagBox.value += " " + tag;
- }
- this.inputTagBox.value += " ";
- },
-
- _checkAddMechPref: function() {
- var prefVal = 1;
- try {
- prefVal = this.prefs.getIntPref( "extensions.ybookmarks@yahoo.addmechanism" );
- }
- catch( e ) { }
- return prefVal;
- },
-
- _traditionalAdd: function() {
-
- yDebug.print( "Ok, need to do traditional add for: url " + this.post.url +
- " and title: " + this.post.title );
-
- var bundleService =
- Components.classes[ "@mozilla.org/intl/stringbundle;1" ].getService(
- Components.interfaces.nsIStringBundleService );
- var bundle =
- bundleService.createBundle( "chrome://ybookmarks/locale/ybookmarks.properties" );
-
- var url;
-
- if (this.post.rss) {
- url = deliciousService.getPostRssUrl(this.post.url, this.post.title,
- this.post.notes, this.config.rssTag);
- } else {
- url = deliciousService.getPostUrl(this.post.url, this.post.title,
- this.post.notes);
- }
- yDebug.print( "Going to open url: " + url, YB_LOG_MESSAGE );
- this._openDelWindow( url, 700, 400 );
- },
-
- _openDelWindow: function( url, width, height ){
- //make it center
- var left = parseInt( ( screen.availWidth / 2 ) - ( width / 2 ) );
- var top = parseInt( ( screen.availHeight / 2 ) - ( height / 2 ) );
- var props = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top +
- ",menubar=0,toolbar=0,scrollbars=1,location=0,status=1,resizable=1"
- var newWindow = window.open( url, "", props );
- setTimeout( "yAddBookMark.delWindowLoaded()", 0 );
- },
-
- delWindowLoaded: function( event ) {
- var wm = Components.classes[ "@mozilla.org/appshell/window-mediator;1" ]
- .getService( Components.interfaces.nsIWindowMediator );
- var ref = wm.getMostRecentWindow( "navigator:browser" );
- ref.focus();
- ref.addEventListener( "unload", yAddBookMark.delWindowClosed, false );
- },
-
- delWindowClosed: function( event ) {
- var syncService = ( Components.classes[this.kSyncServiceContractID].
- getService(Components.interfaces.nsIYBookmarkSyncService) );
- syncService.sync(false);
- },
-
- /**
- * Clone of addBookmarkForBrowser from firefox source
- * This is necessary to override the bookmarking functionality
- */
- addBookmarkForTabBrowser: function( aTabBrowser ) {
-
- var webNav = aTabBrowser.webNavigation;
- var url = webNav.currentURI.spec;
- var title, description, charset;
- try {
- var doc = webNav.document;
- title = doc.title || url;
- charset = doc.characterSet;
- description = ybookmarksUtils.getDescriptionFromDocument( doc );
- } catch ( e ) {
- title = url;
- }
-
- this.open( url, title, charset, false, description );
- },
-
- addLiveBookmark: function(event) {
- var url = event.target.getAttribute('feed');
- var doc = gBrowser.selectedBrowser.contentDocument;
- var title = doc.title;
- var description = ybookmarksUtils.getDescriptionFromDocument(doc);
- event.stopPropagation();
- this.open(doc.baseURI, title, "", false, description, url);
- },
-
- /* copy of FF FeedHandler.buildFeedList. Required to add delicious options for adding livemarks */
- ybuildFeedList: function(arg) {
- var menuPopup = null;
- var addDeliciousOptions = true;
- var ff1_5 = false;
- if (arg instanceof MouseEvent) {
- menuPopup = arg.target;
- ff1_5 = true;
- } else {
- menuPopup = arg;
- }
- var parent = menuPopup.parentNode;
- if (parent) {
- if (parent.id == "subscribeToPageMenupopup") {
- addDeliciousOptions = false;
- }
- }
- var feeds = gBrowser.selectedBrowser.feeds;
- if (feeds == null) {
- menuPopup.parentNode.removeAttribute("open");
- return false;
- }
-
- while (menuPopup.firstChild)
- menuPopup.removeChild(menuPopup.firstChild);
-
- /**
- * Attempt to generate a list of unique feeds from the list of feeds
- * supplied by the web page. It is fairly common for a site to supply
- * feeds in multiple formats but with divergent |title| attributes so
- * we need to make a rough pass at trying to not show a menu when there
- * is in fact only one feed. If this is the case, by default select
- * the ATOM feed if one is supplied, otherwise pick the first one.
- * @param feeds
- * An array of Feed info JS Objects representing the list of
- * feeds advertised by the web page
- * @returns An array of what should be mostly unique feeds.
- */
- function harvestFeeds(feeds) {
- var feedHash = { };
- for (var i = 0; i < feeds.length; ++i) {
- var feed = feeds[i];
- if (!(feed.type in feedHash))
- feedHash[feed.type] = [];
- feedHash[feed.type].push(feed);
- }
- var mismatch = false;
- var count = 0;
- var defaultType = null;
- for (var type in feedHash) {
- // The default type is whichever is listed first on the web page.
- // Nothing fancy, just something that works.
- if (!defaultType) {
- defaultType = type;
- count = feedHash[type].length;
- }
- if (feedHash[type].length != count) {
- mismatch = true;
- break;
- }
- count = feedHash[type].length;
- }
- // There are more feeds of one type than another - this implies the
- // content developer is supplying multiple channels, let's not do
- // anything fancier than this and just return the full set.
- if (mismatch)
- return feeds;
-
- // Look for an atom feed by default, fall back to whichever was listed
- // first if there is no atom feed supplied.
- const ATOMTYPE = "application/atom+xml";
- return ATOMTYPE in feedHash ? feedHash[ATOMTYPE] : feedHash[defaultType];
- }
-
- var feeds = harvestFeeds(feeds);
- var askForReader = true;
- try {
- var feedHandler = this.prefs.getCharPref("browser.feeds.handler");
- askForReader = (feedHandler == "ask");
- } catch ( e ) { }
-
- if ((!askForReader) && (feeds.length == 1)) {
- return false;
- }
- if (parent.id == "feed-button") {
- parent.removeAttribute("feed");
- }
-
- var hideFFBMMenu = false;
- try {
- hideFFBMMenu = this.prefs.getBoolPref("extensions.ybookmarks@yahoo.original.ui.hide");
- } catch ( e ) { }
-
- var strings = document.getElementById("ybookmarks-strings");
-
- // Build the menu showing the available feed choices for viewing.
- for (var i = 0; i < feeds.length; ++i) {
- var feedInfo = feeds[i];
- var baseTitle = feedInfo.title || feedInfo.href;
-
- if ((!ff1_5) || ((ff1_5) && (hideFFBMMenu == false))) {
- var menuItem = document.createElement("menuitem");
- var labelStr;
- try {
- labelStr = gNavigatorBundle.getFormattedString("feedShowFeed",[baseTitle]);
- } catch(e) {
- labelStr = gNavigatorBundle.getFormattedString("feedShowFeedNew",[baseTitle]);
- }
- menuItem.setAttribute("label", labelStr);
- menuItem.setAttribute("feed", feedInfo.href);
- menuItem.setAttribute("tooltiptext", feedInfo.href);
- menuPopup.appendChild(menuItem);
- }
- if ((askForReader) && (addDeliciousOptions == true)) {
- var menuItem = document.createElement("menuitem");
- var labelStr = strings.getFormattedString("extensions.ybookmarks.add.livemark", [baseTitle]);
- menuItem.setAttribute("label", labelStr);
- menuItem.setAttribute("feed", feedInfo.href);
- menuItem.setAttribute("tooltiptext", feedInfo.href);
- menuItem.setAttribute("oncommand", "yAddBookMark.addLiveBookmark(event)");
- menuPopup.appendChild(menuItem);
- }
- }
- return true;
- },
-
- resolveKeyword: function(aURL, aPostDataRef) {
- var keyword = aURL.toLowerCase();
- var ds = this.localStore.getDataSource();
- if(!RDF) {
- //required for FF3
- var RDF = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(Components.interfaces.nsIRDFService);
- }
- var source = ds.GetSource(RDF.GetResource("http://home.netscape.com/NC-rdf#ShortcutURL"),
- RDF.GetLiteral(keyword), true);
- if (source) {
- var url = ds.GetTarget(source,
- RDF.GetResource("http://home.netscape.com/NC-rdf#URL"), true);
- if (url) {
- var node = ds.GetTarget(source,
- RDF.GetResource("http://home.netscape.com/NC-rdf#PostData"), true);
- if (node) {
- var postDataString = node.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- if (postDataString.length > 0) {
- aPostDataRef.value = postDataString;
- }
- }
-
- return url.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- }
- }
- return null;
- },
-
- getShortcutOrURI: function(aURL, aPostDataRef) {
- try {
- this._getLocalStore();
- var shortcutURL = this.resolveKeyword(aURL, aPostDataRef);
- if (!shortcutURL) {
- var aOffset = aURL.indexOf(" ");
- if (aOffset > 0) {
- var cmd = aURL.substr(0, aOffset);
- var text = aURL.substr(aOffset+1);
- shortcutURL = this.resolveKeyword(cmd, aPostDataRef);
- if (shortcutURL && text) {
- var encodedText = null;
- var charset = "";
- const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/;
- var matches = shortcutURL.match(re);
- if (matches) {
- shortcutURL = matches[1];
- charset = matches[2];
- }
- else if (/%s/.test(shortcutURL) ||
- (aPostDataRef && /%s/.test(aPostDataRef.value))) {
- try {
- charset = this.getLastCharset(shortcutURL);
- } catch (ex) {
- }
- }
-
- if (charset)
- encodedText = escape(convertFromUnicode(charset, text));
- else // default case: charset=UTF-8
- encodedText = encodeURIComponent(text);
-
- if (aPostDataRef && aPostDataRef.value) {
- // XXXben - currently we only support "application/x-www-form-urlencoded"
- // enctypes.
- aPostDataRef.value = unescape(aPostDataRef.value);
- if (aPostDataRef.value.match(/%[sS]/)) {
- aPostDataRef.value = getPostDataStream(aPostDataRef.value,
- text, encodedText,
- "application/x-www-form-urlencoded");
- }
- else {
- shortcutURL = null;
- aPostDataRef.value = null;
- }
- }
- else {
-
- if (/%[sS]/.test(shortcutURL))
- shortcutURL = shortcutURL.replace(/%s/g, encodedText)
- .replace(/%S/g, text);
- else {
- // don't do any substitution, but still return the expanded url
- }
- }
- }
- }
- }
-
- var origURL = this.originalGetShortcutOrURI(aURL, aPostDataRef);
-
- if (shortcutURL && origURL != aURL) {
- var warnCheck = this.prefs.getBoolPref("extensions.ybookmarks@yahoo.original.keyword.conflicts.warn");
- if (warnCheck) {
- var stringService = Components.classes["@mozilla.org/intl/stringbundle;1"].
- getService(Components.interfaces.nsIStringBundleService);
- var strings = stringService.createBundle("chrome://ybookmarks/locale/ybookmarks.properties");
-
- var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
- getService(Components.interfaces.nsIPromptService);
- var text = strings.GetStringFromName("extensions.ybookmarks.original.keyword.conflicts.text");
- var warn = strings.GetStringFromName("extensions.ybookmarks.original.keyword.conflicts.warn");
- var warnCheck = { value: true };
-
- promptService.alertCheck(window, "Delicious", text, warn, warnCheck);
-
- if (!warnCheck.value) {
- this.prefs.setBoolPref("extensions.ybookmarks@yahoo.original.keyword.conflicts.warn", false);
- }
-
- }
- }
-
- if (shortcutURL && origURL == aURL) {
- return shortcutURL;
- } else {
- yDebug.print("overridden getShortcutOrURI... Delegating");
- return origURL;
- }
- } catch (e) {
- yDebug.print("getShortcutOrURI(): " + e, YB_LOG_MESSAGE);
- try {
- return this.originalGetShortcutOrURI(aURL, aPostDataRef);
- } catch (e) {
- yDebug.print("getShortcutOrURI(): Even worse! error with this.originalGetShortcutOrURI(): " + e, YB_LOG_MESSAGE);
- return aURL;
- }
- }
-
- },
-
- addHooks: function() {
- yDebug.print("Adding hooks.", YB_LOG_MESSAGE);
- try {
- // put in our shortcut url handler
- var topWindow = ybookmark_Utils._getTopWindow();
-
- // the mac seems to add the hooks in weird cases. For instance, if you bring up the
- // preferences window, it'll break the addressbar. This is probably due
- // to the overlay being included in every new window ala this in chrome.manifest
- // overlay chrome://browser/content/macBrowserOverlay.xul chrome://ybookmarks/content/ybookmarksOverlay.xul
- var addHooks = true;
- if (ybookmarksUtils.getPlatform() == YB_PLATFORM_MAC) {
- if ( !(topWindow && window.content) ) {
- // topWindow.browserDOMWindow && <-- took out this condition. fix for bug 1071605
- addHooks = false;
- }
- }
- if (!addHooks) {
- return;
- }
-
-
- if (topWindow) {
- yDebug.print("Adding Livemark Hook.", YB_LOG_MESSAGE);
- topWindow.FeedHandler.buildFeedList =
- function(event) { return yAddBookMark.ybuildFeedList(event); };
- }
-
- if (yAddBookMark.originalGetShortcutOrURI == null) {
- yDebug.print("Adding ShortuctURI Hook.", YB_LOG_MESSAGE);
-
- yAddBookMark.originalGetShortcutOrURI = topWindow.getShortcutOrURI;
- topWindow.getShortcutOrURI = function(aURL, aPostDataRef) {
- return yAddBookMark.getShortcutOrURI(aURL, aPostDataRef);
- };
- }
- /* var hideFFBMUI = false;
- var remapShortcutKeys = false;
- try {
- hideFFBMUI = this.prefs.getBoolPref("extensions.ybookmarks@yahoo.original.ui.hide");
- remapShortcutKeys = this.prefs.getBoolPref("extensions.ybookmarks@yahoo.original.keybindings.remap");
- } catch ( e ) { }
-
- if (hideFFBMUI || remapShortcutKeys) {
- var docelem = document.getElementById("addBookmarkAsKb");
- docelem.setAttribute("command", "cmd_yb_bookmark_this_page");
- docelem = document.getElementById("viewBookmarksSidebarKb");
- docelem.setAttribute("command", "viewYBookmarksSidebar");
- }
- */
- } catch (e) {
- yDebug.print("yAddBookmarks.addHooks():" + e, YB_LOG_MESSAGE);
- }
- },
-
- // This function has code copied from browser.js. Alas, there seems to be no
- // cleaner way to do this. The browser code is hardcoded to open it's own
- // add bookmark dialog. The code here is the same except for the last part
- // (where this function opens our dialog).
- createSearchKeywordBookmark: function () {
- yDebug.print( "yAddBookMark.createSearchKeywordBookmark called!" );
- var node = document.popupNode;
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- var uri = ioService.newURI(node.ownerDocument.URL, node.ownerDocument.characterSet, null);
-
- var keywordURL = ioService.newURI(node.form.getAttribute("action"), node.ownerDocument.characterSet, uri);
- var spec = keywordURL.spec;
- var postData = "";
- var i, e;
-
- if (node.form.method.toUpperCase() == "POST" &&
- (node.form.enctype == "application/x-www-form-urlencoded" || node.form.enctype == "")) {
- for (i=0; i < node.form.elements.length; ++i) {
- e = node.form.elements[i];
- if (e.type) {
- if (e.type.toLowerCase() == "text" || e.type.toLowerCase() == "hidden" ||
- e instanceof HTMLTextAreaElement)
- postData += escape(e.name + "=" + (e == node ? "%s" : e.value)) + "&";
- else if (e instanceof HTMLSelectElement && e.selectedIndex >= 0)
- postData += escape(e.name + "=" + e.options[e.selectedIndex].value) + "&";
- else if ((e.type.toLowerCase() == "checkbox" ||
- e.type.toLowerCase() == "radio") && e.checked)
- postData += escape(e.name + "=" + e.value) + "&";
- }
- }
- }
- else {
- spec += "?" + escape(node.name) + "=%s";
- for (i=0; i < node.form.elements.length; ++i) {
- e = node.form.elements[i];
- if (e == node) { // avoid duplication of the target field value, which was populated above.
- continue;
- }
- if (e.type) {
- if (e.type.toLowerCase() == "text" || e.type.toLowerCase() == "hidden" ||
- e instanceof HTMLTextAreaElement)
- spec += "&" + escape(e.name) + "=" + escape(e.value);
- else if (e instanceof HTMLSelectElement && e.selectedIndex >= 0)
- spec += "&" + escape(e.name) + "=" + escape(e.options[e.selectedIndex].value);
- else if ((e.type.toLowerCase() == "checkbox" ||
- e.type.toLowerCase() == "radio") && e.checked)
- spec += "&" + escape(e.name) + "=" + escape(e.value);
- }
- }
- }
- this.open( spec, "", null, null, null, null, false, postData, true );
- },
-
- /**
- * Get the top most browser window
- **/
- _getTopWindow : function() {
- var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
- var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
- var topWindow = windowManagerInterface.getMostRecentWindow( "navigator:browser" );
-
- return topWindow;
- },
-
- bookmarkTransactionsObserver : {
-
- observe: function(subject, topic, data) {
-
- if (topic == "ybookmark.processTransactions") {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
- getService(Components.interfaces.nsIWindowMediator);
- var recentWindow = wm.getMostRecentWindow("navigator:browser");
- if (recentWindow != window) {
- return;
- }
-
- window.setTimeout(yAddBookMark.processTransactions, 0);
- }
- }
- },
-
- processTransactions : function() {
-
- if(this != yAddBookMark) {
- yAddBookMark.processTransactions();
- return;
- }
-
- this._getSyncService();
- this.syncService.processTransactions();
- },
-
- saveSearchString: function () {
- var temp = this.inputTagBox.value.split(" ");
- temp.pop();
- this.inputTagBox.setAttribute("savedSearchString", temp.join(" "));
- },
-
- prependSavedSearchString: function () {
- var tmp = this.inputTagBox.getAttribute("savedSearchString");
-
- if(tmp) tmp = tmp + " ";
-
- this.inputTagBox.value = tmp + this.inputTagBox.value;
- }
-
- };
-
-